#ifndef JSON_DATA_HPP
#define JSON_DATA_HPP

#include <jsoncpp/json/json.h>
#include <string>
#include <cstring>
#include <iostream>

namespace Wall_Localization{

    class PoseJsonConverter
    {

    public:

        PoseJsonConverter();
        ~PoseJsonConverter() = default;
        

        //设置速度值
        void set_from_pose(double x, double y, double theta);

        //生成并返回json消息字符串
        std::string get_json_msg() const;

        // 清空数据
        void clear();

    private:

        double pose_x_;
        double pose_y_;
        double pose_theta_;

        // 内部辅助函数
        void initialize_members();
    
    };

    // 内联实现
    inline PoseJsonConverter::PoseJsonConverter()
    {
        initialize_members();
    }

    // 初始化数据
    inline void PoseJsonConverter::initialize_members()
    {
        pose_x_ = 0.0;
        pose_y_ = 0.0;
        pose_theta_ = 0.0;
    }


    inline void PoseJsonConverter::set_from_pose(double x, double y, double theta)
    {
        pose_x_ = x;
        pose_y_ = y;
        pose_theta_ = theta;
    }


    inline std::string PoseJsonConverter::get_json_msg() const
    {
        Json::Value json_val;
        json_val["pose_x"] = pose_x_;
        json_val["pose_y"] = pose_y_;
        json_val["pose_theta"] = pose_theta_;
        
        Json::StreamWriterBuilder builder;
        builder["indentation"] = ""; // 紧凑格式
        return Json::writeString(builder, json_val);
    }


    inline void PoseJsonConverter::clear()
    {
        initialize_members();
    }

}



#endif